package com.drools.demo.server;

import com.drools.demo.entity.SubjectScore;
import com.sun.istack.internal.NotNull;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author czq
 * @Package com.drools.demo.server
 * @Date 2024/8/27 14:13
 * @description:
 */
@Service
public class SubjectService {

    @Resource
    private KieContainer kieContainer;

    //设置模拟分数
    public List<SubjectScore> setScore() {
        List<SubjectScore> list = new ArrayList<>();
        SubjectScore subjectScore1 = new SubjectScore();
        subjectScore1.setScore(80);
        subjectScore1.setSubjectName("科目1");
        subjectScore1.setWidget(0.2);
        subjectScore1.setId(1);
        SubjectScore subjectScore2 = new SubjectScore();
        subjectScore2.setScore(80);
        subjectScore2.setSubjectName("科目1");
        subjectScore2.setWidget(0.2);
        subjectScore2.setId(2);
        SubjectScore subjectScore3 = new SubjectScore();
        subjectScore3.setScore(80);
        subjectScore3.setSubjectName("科目1");
        subjectScore3.setWidget(0.4);
        subjectScore3.setId(3);
        SubjectScore subjectScore4 = new SubjectScore();
        subjectScore4.setScore(80);
        subjectScore4.setSubjectName("科目1");
        subjectScore4.setWidget(0.2);
        subjectScore4.setId(4);

        list.add(subjectScore1);
        list.add(subjectScore2);
        list.add(subjectScore3);
        list.add(subjectScore4);
        return list;
    }

    //根据评分规则获取最终得分
    public Integer calculate(){
        List<SubjectScore> list = setScore();
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.insert(list);
        kieSession.fireAllRules();
        kieSession.dispose();
        System.out.println(list);
        return 0;
    }


    @NotNull
    public Integer getTotalScore() {
        return calculate();
    }
}
